var elm;

//call by script
suggest = function (domElm, inputString){
	var left = $(domElm).position().left;// + $("#allProfile").parent().position().left;
	var top = $(domElm).position().top + $(domElm).height();// + $("#allProfile").parent().position().top;
	suggestOnPlace(domElm, inputString, 'load', left, top);
}

suggestOnPage = function (domElm, inputString){
	var left = $(domElm).position().left;// + $("#allProfile").parent().position().left-157;
	var top = $(domElm).position().top + $(domElm).height();// + $("#allProfile").parent().position().top - 230;
	suggestOnPlace(domElm, inputString, 'load', left, top);
}

suggestOnPlace = function (domElm,inputString,className,left,top){
	if($("#paymode").val() == "CreditCard"){
		if($("#paymode").val() != "0"){
			if(inputString.length == 0) {
				$('#suggestions').fadeOut();
			} else {
				elm = domElm;
				$(domElm).addClass(className);
				$("#suggestions").css({"top": top + "px", "left": left + "px" });
				var link = "/CreditCardService?func=suggestCardNumber&text=" + inputString;
				
				$.ajax({
					// Call
					url : link,
					type : "get",
					data : {
						format : "json"
					},
					datatype : "json",
					timeout : 2000,

					// if Call Success //
					success : function(data) {
						var objArray = new Array();
						
						if(data != ""){
							objArray = JSON.parse(data);
							var sumtext = "";
								if(data.length >0) {
									for(var i =0 ;i<objArray.length;i++){
										sumtext +=  "<div id=\"suggestionsList"+i+"\"  class=\"suggestlist\" " +
												"name=\"suggestionsList"+i+"\" onclick=\"suggestselect(this)\">"+objArray[i]+"</div>"
									}						
									$('#suggestions').fadeIn();
									var top_value = ($("#payCcNo").offset().top-80);
							    	var left_value = ($("#payCcNo").offset().left);
									$('#suggestions').offset({ top: top_value, left: left_value });	
									$('#suggestions').html("");
									$("#suggestions").append(sumtext);
									$("#suggestions").show();
									$("#suggestions").css("z-index","210000");
									$(domElm).removeClass('load');
								}
						}else{
							FadeOut();
						}
					},

				});
			}
		}else{
			alert("chose paytype ,,please");
		}
	}
}

function suggestselect(thisValue){
	$("#payCcNo").val($("#"+thisValue.id).html());
}

fill = function (thisValue) {
	$(elm).val(thisValue);
	setTimeout("$('#suggestions').fadeOut();", 0);
}

FadeOut = function (thisValue) {
	setTimeout("$('#suggestions').fadeOut();", 0);
}

function checkValue(){
	if($("#paymode").val() == "CreditCard" && $("#paytype").val() != "0"){
		FadeOut();
		var chk = false;
		for(var i=0;i<$('#suggestions').find("div").size();i++){
			if($("#payCcNo").val() == $('#suggestions').find("div")[i]){
				chk = true;
				break;
			}
		}
		if(chk == false){
			payTypeChange();
		}
	}
}